unit frmClientManager;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ImgList, Vcl.ComCtrls, Vcl.StdCtrls,
  Vcl.ExtCtrls, System.Win.ScktComp, mcCommands, mClientSession;

type
  TfrmManager = class(TForm)
    lv1: TListView;
    il1: TImageList;
    pnl1: TPanel;
    lbl1: TLabel;
    pnl2: TPanel;
    lbl2: TLabel;
    pnl3: TPanel;
    lbl3: TLabel;
    pnl4: TPanel;
    lbl4: TLabel;
    procedure lv1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);

    procedure interpretPackage(com: RCommand);

  private
    { Private declarations }
    cs: TClientSession;
  public
    { Public declarations }
    procedure setcs(css: TClientSession);
  end;

var
  frmManager: TfrmManager;
  panellist: TList;

const
  ANIMATION_SPEED = 200;

  S_PINGSENT = $387;

implementation

{$R *.dfm}

procedure TfrmManager.setcs(css: TClientSession);
begin
  cs := css;
end;


procedure TfrmManager.interpretPackage(com: RCommand);
var
  ack: RAck;
begin
  if com.magic <> MAGIC_DWORD then
  begin
    ack.magic := COM_RESEND_COM;
    ack.ack := COM_RESEND_COM;
  end;
  ack.magic := MAGIC_DWORD;

  case com.command of
    COM_FILE_CLI:
      begin
        ack.ack := com.checksum;
      end;
    COM_SCREEN:
      begin
        ack.ack := com.checksum;
      end;
  end;
end;

procedure TfrmManager.FormCreate(Sender: TObject);
var
  i: integer;
begin
  panellist :=  TList.Create;

  with panellist do
  begin
    Add(pnl1);
    Add(pnl2);
    Add(pnl3);
    Add(pnl4);
  end;

  for i := 0 to panellist.Count - 1 do
    TPanel(panellist.Items[i]).Visible := False;
end;

procedure TfrmManager.FormDestroy(Sender: TObject);
begin
  panellist.Free;
end;

procedure TfrmManager.lv1Click(Sender: TObject);
var
  lvi: TListItem;
  pnl: TPanel;
  index, i: Integer;
begin
  for i := 0 to panellist.Count - 1 do
  begin
    AnimateWindow(TPanel(panellist.Items[i]).Handle, ANIMATION_SPEED, AW_VER_POSITIVE OR AW_SLIDE OR AW_HIDE);
  end;

  lvi := lv1.Selected;
  index := lv1.Items.IndexOf(lvi);
  //ShowMessage(IntToStr(index));

  pnl := TPanel(panellist.Items[index]);

  AnimateWindow(pnl.handle, ANIMATION_SPEED, AW_VER_NEGATIVE OR AW_SLIDE);
end;

end.
